import { createRouter, createWebHistory } from 'vue-router'
import SnakeMenu from '@/game/snake-game-v1.1.2.vue'


// import Home from '@/views/Home.vue' 使用配置的@路径别名

const routes = [
    // {
    //     path: '/',
    //     name: 'Home',
    //     component: Home
    // },
    {
        path: '/about',
        name: 'About',
        component: () => import('@/views/About.vue') // 懒加载
    },
    {
        path: '/Snake-game',
        name: 'Snake-game',
        component: () => import('@/game/enhanced-snake-game.vue'),
        meta: { requiresStart: true },
        beforeEnter: (to, from, next) => {
            if (from.name === 'SnakeMenu' && to.meta.requiresStart) {
                next()
            } else {
                next({ name: 'SnakeMenu' }) // 重定向回菜单页
            }
        }
    },
    {
        path: '/snake-menu',
        name: 'SnakeMenu',
        component: SnakeMenu
    },
    {
        path: '/',
        name: 'SnakeMenus',
        component: SnakeMenu
    }
]

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes
})

export default router